var environment=_gl.environment||"production";
var ajaxUrl={
    "local":{
        "settimeoutTime":1400,
        "dataList_prev":_gl._host_res+"/res/js/data/courseList.json",
        "dataList_current":_gl._host_res+"/res/js/data/courseList_1.json",
        "dataList_next":_gl._host_res+"/res/js/data/courseList_1.json"
    },
    "production":{
        "settimeoutTime":0,
        "dataList_prev":"",
        "dataList_current":"",
        "dataList_next":""
    }
};
$(function(){
    var _type = "current";

    _fridayTable.setTableTr({
        "url":ajaxUrl[environment]["dataList_"+_type],
        "columns":[
            {
                "fieldName":null,
                "dom":"seq"
            },
            {
                "fieldName":"title"
            },
            {
                "fieldName":"course_time",
                "formatFun": _helper.timeFormat
            },
            {
                "fieldName":"create_time",
                "formatFun": _helper.timeFormat
            },
            {
                "fieldName":"status",
                "formatFun":  _helper.statusFormat
            },
            {
                "fieldName":null,
                "renderFun": function (val) {
                    return '<a class="btn btn-success btn-sm btn-operation btn-query" href="#"><span class="glyphicon glyphicon-search"></span>查看</a>';
                }
            }
        ]
    });
    _fridayTable.searchData();


    //标签页
    $(".nav-tabs>li").on("click",function(e){
        e.stopPropagation();
        var $this = $(this);
        $this.addClass("active").siblings().removeClass("active");
        _type = $this.find("a").attr("href").replace("#","");
        _fridayTable.searchData({"url":ajaxUrl[environment]["dataList_"+_type]});
    });

    /*页面查看课程*/
    $(document).on( 'click','a,button', function (e) {
        e.stopPropagation();
        $removeTr = $(this).parents("tr");
        var itemId = $removeTr.find("input[type='hidden']").val();
        if($(this).hasClass("btn-query")){
            //列表里面的课程删除
            queryItem(itemId);

        }
    });

    //进入编辑页面
    function gotoDetail(obj){
        parent.addNewIframe({"href":_gl._host_res+"/course/detail.html?flag="+((obj&&obj.flag)||add)+"&id="+((obj&&obj.id)||""),"text":(obj&&obj.text)||"课程详情"});
    }

    //查看课程
    function queryItem(id){
        gotoDetail({"flag":"query","id":id,"text":"课程详情"});
    }
});